< previous page page_154 next page >

Page 154
' Retrieve a system error change.
Private Function GetErrorString(ByVal LastErrorValue As Long) As String
   Dim bytes&
   Dim s As String
   s = String$(129, 0)
   bytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, ByVal _
   0&, LastErrorValue, 0, s$, 128, 0)
   If bytes > 0 Then
      GetErrorString = Left$(s, bytes)
   End If
End Function
The FormatMessage function returns the number of characters in the string, so you can simply use the Left$ function to retrieve the valid characters up to the terminating NULL character.
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
3 See Tutorial 5, "The ByVal Keyword: The Solution to 90 Percent of All API Problems," for further information on using the ByVal keyword with parameters declared As Any.

 
< previous page page_154 next page >